package com.leejxx.kafka.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @Author LeeJx
 * @ClassName HelloListener
 * @Description TODO
 * @date 2021/2/27 12:20
 * @Version 1.0
 */
@Component
public class HelloListener {
    @KafkaListener(topics = {"kafka-hello"})
    public void receiveMessage(ConsumerRecord<?, ?> record) {
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if (optional.isPresent()) {
            System.out.println(record.value());
        }
    }
}
